<template>
<h1>表单组件</h1>
  <el-form style="width: 500px; margin: 0 auto;" label-width="80">
    <el-form-item label="用户名">
      <el-input v-model="name" placeholder="请输入姓名"></el-input>
    </el-form-item>
      <el-form-item label="密码">
        <el-input show-password v-model="password" placeholder="请输入密码"></el-input>
      </el-form-item>
    <el-form-item label="性别">
      <el-radio-group v-model="sex">
        <el-radio-button label="1">男</el-radio-button>
        <el-radio-button label="0">女</el-radio-button>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="所在地">
      <el-select v-model="city" placeholder="请选择城市">
        <el-option label="北京" value="bj"></el-option>
        <el-option label="上海" value="sh"></el-option>
        <el-option label="广州" value="gz"></el-option>
        <el-option label="深圳" value="sz"></el-option>
        <el-option label="重庆" value="cq"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="管理员">
      <el-switch v-model="isAdmin" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
    </el-form-item>
    <el-form-item>
      <el-button type="success" @click="add">点我提交</el-button>
    </el-form-item>



  </el-form>
  <br>
  <table border="1" align="center">
    <tr>
      <th>序号</th>
      <th>用户名</th>
      <th>密码</th>
      <th>性别</th>
      <th>城市</th>
      <th>是否管理员</th>
    </tr>
    <tr v-for="(item, index) in p" :key="index">
      <td>{{index+1}}</td>
      <td>{{item.name}}</td>
      <td>{{item.password}}</td>
      <td>{{item.sex}}</td>
      <td>{{item.city}}</td>
      <td>{{item.isAdmin}}</td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";

const name = ref('')
const password = ref('')
const sex = ref('0')
const city = ref('')
const isAdmin = ref(false)
const p = ref([])
const emp = ref([])
const add = () => {
  p.value.push({
    name: name.value,
    password: password.value,
    sex: sex.value,
    city: city.value,
    isAdmin: isAdmin.value
  });
  emp.value = {name: '',
  password:'',
  sex: '',
  city: '',
  isAdmin: false}
  console.log(name.value, password.value, sex.value, city.value, isAdmin.value)
}
</script>

<style scoped>

</style>